package com.talent.service.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.talent.model.entity.sys.SysMenu;
import com.talent.model.entity.sys.SysUser;
import com.talent.service.auth.mapper.SysUserMapper;
import com.talent.service.auth.service.ISysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName：ResponseEnum
 * @Author: hszhou
 * @Date: 2024/10/21 13:35
 * @Description: 用户接口实现
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {

    private Logger logger = LoggerFactory.getLogger(getClass());
    @Override
    public SysUser selectUserByUsername(String username) {
        LambdaQueryWrapper<SysUser> eq = new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, username);
        SysUser user = this.baseMapper.selectOne(eq);
        return user;
    }
    @Override
    public List<String> getPermission(Long userId) {

      return this.baseMapper.getPermissions(userId)
                .stream().filter(e->e.getType()== 2)
                .map(SysMenu::getCode).collect(Collectors.toList());

    }

}
